package com.example.baiduai.service.impl;

import com.example.baiduai.dto.AIResult;
import com.example.baiduai.dto.AiDto;
import com.example.baiduai.factroy.PayMannerFactroy;
import com.example.baiduai.interfaces.Constat;
import com.example.baiduai.pojo.AbnormalPojo;
import com.example.baiduai.service.BaiduAIService;
import com.example.baiduai.utils.GooGleCacheUtils;
import com.example.baiduai.utils.HttpUtils;
import com.example.baiduai.utils.ObjectUtils;
import com.example.baiduai.utils.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;


@Service
public class BaiduAIServiceImpl implements BaiduAIService {


    @Autowired
    private PayMannerFactroy payMannerFactroy;

    @Override
    public void payDetectionCallback(AiDto aicVDto) {


        if(ObjectUtils.isNotEmpty(aicVDto.getResult())){
            List<String> labelNames = aicVDto.getResult().stream().map(AIResult::getLabel_name).collect(Collectors.toList());
            aicVDto.setLabelNames(labelNames);
            // 支付判断
            payMannerFactroy.payMannerJudgment(aicVDto);
            if(labelNames.contains("扫私人二维码")){
                Boolean qrCodeCache = GooGleCacheUtils.isQRCodeCache(Constat.prefix.QR_CODE_PREFIX + aicVDto.getDevice_id());
                if(ObjectUtils.isEmpty(qrCodeCache)){  // 扫私人二维码的异常
                    GooGleCacheUtils.qRCodeCachePut(Constat.prefix.QR_CODE_PREFIX + aicVDto.getDevice_id());
//                    AbnormalPojo abnormalPojo = new AbnormalPojo(aicVDto.getDevice_id(), TimeUtils.getCurrentTime_ymd_hms(), 1, 2);
//                    HttpUtils.doPostJson(Constat.IP+Constat.URL,abnormalPojo);
                }
            }

        }

    }



}
